#!/bin/bash

set -x
(
  cd ../ || exit 1
  ./gradlew :http-server:shadowJar :game-headless:shadowJar :lobby-db:release

  ANSIBLE_ROLES_FOLDER="infrastructure/ansible/roles"

  function deployShadowJar() {
    local -r gradleProjectName="$1"
    local -r ansibleRoleName="$2"

    mkdir -p "$ANSIBLE_ROLES_FOLDER/$ansibleRoleName/files/"
    cp "$gradleProjectName"/build/libs/* "$ANSIBLE_ROLES_FOLDER/$ansibleRoleName/files/"
  }

  deployShadowJar "http-server" "http_server"
  deployShadowJar "game-headless" "bot"

  mkdir -p "$ANSIBLE_ROLES_FOLDER/flyway/files/"
  cp lobby-db/build/artifacts/* "$ANSIBLE_ROLES_FOLDER/flyway/files/"
)
